package com.example.workbench.common.Result;



import com.example.workbench.common.emus.AuthenticationError;
import com.example.workbench.common.emus.BusinessError;
import com.example.workbench.common.emus.SuccessReturnCode;
import com.example.workbench.common.vo.BaseResultVo;

import java.time.LocalDateTime;


public class ResultFactory {

    private static final Boolean SUCCESS_RETURN = true;

    private static final Boolean ERROR_RETURN = false;

    public static BaseResultVo successResult(){
        BaseResultVo result = BaseResultVo.instance();
        result.setCode(SuccessReturnCode.NORMAL.getCode());
        result.setMessage(SuccessReturnCode.NORMAL.getDesc());
        result.setTime(LocalDateTime.now());
        result.setSuccess(SUCCESS_RETURN);
        return result;
    }
    public static BaseResultVo successResult(Object data){
        BaseResultVo result = BaseResultVo.instance();
        result.setData(data);
        result.setCode(SuccessReturnCode.NORMAL.getCode());
        result.setMessage(SuccessReturnCode.NORMAL.getDesc());
        result.setTime(LocalDateTime.now());
        result.setSuccess(SUCCESS_RETURN);
        return result;
    }

    public static BaseResultVo successResult(SuccessReturnCode successReturnCode){
        BaseResultVo result = BaseResultVo.instance();
        result.setMessage(successReturnCode.getDesc());
        result.setCode(successReturnCode.getCode());
        result.setTime(LocalDateTime.now());
        result.setSuccess(SUCCESS_RETURN);
        return result;
    }

    public static  BaseResultVo successResult(SuccessReturnCode successReturnCode,Object data){
        BaseResultVo result = BaseResultVo.instance();
        result.setCode(successReturnCode.getCode());
        result.setMessage(successResult().getMessage());
        result.setData(data);
        result.setTime(LocalDateTime.now());
        result.setSuccess(SUCCESS_RETURN);
        return result;
    }

    public static BaseResultVo errorResult(BusinessError businessError){
        BaseResultVo result = BaseResultVo.instance();
        result.setCode(businessError.getCode());
        result.setMessage(businessError.getDesc());
        result.setTime(LocalDateTime.now());
        result.setSuccess(ERROR_RETURN);
        return result;
    }

    public static BaseResultVo errorResultValid(BusinessError businessError,String message){
        BaseResultVo result = BaseResultVo.instance();
        result.setCode(businessError.getCode());
        result.setTime(LocalDateTime.now());
        result.setMessage(message);
        result.setSuccess(ERROR_RETURN);
        return result;
    }

    public static BaseResultVo errorResultBusiness(String msg){
        BaseResultVo result = BaseResultVo.instance();
        result.setCode(10000);
        result.setSuccess(ERROR_RETURN);
        result.setTime(LocalDateTime.now());
        result.setMessage(msg);
        return result;
    }

    public static BaseResultVo errorResultAuthentication(AuthenticationError errorCode){
        BaseResultVo result = BaseResultVo.instance();
        result.setCode(errorCode.getCode());
        result.setSuccess(ERROR_RETURN);
        result.setTime(LocalDateTime.now());
        result.setMessage(errorCode.getDesc());
        return result;
    }
}
